package com.android.lovingpet.mine.pet.view;


import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.lovingpet.R;
import com.android.lovingpet.base.BaseFragment;
import com.android.lovingpet.bean.Pet;
import com.android.lovingpet.mine.pet.IPetContract;
import com.android.lovingpet.mine.pet.PetPresenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by ikata on 2018/5/5.
 */

public class PetDetailsFragment extends BaseFragment<IPetContract.View, PetPresenter> implements IPetContract.View, View.OnClickListener {

    @BindView(R.id.iv_head)
    ImageView ivHead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_sex)
    TextView tvSex;
    @BindView(R.id.tv_praise)
    TextView tvPraise;
    @BindView(R.id.tv_type)
    TextView tvType;
    Unbinder unbinder;
    @BindView(R.id.tv_info)
    TextView tvInfo;
    private Pet pet = null;

    @Override
    public void next() {

    }

    @Override
    public void showMyPet(Pet pet) {

    }

    @Override
    protected int setContentView() {
        return R.layout.fragment_pet_details;
    }

    @Override
    protected void onCreateView(View view) {
        unbinder = ButterKnife.bind(this, view);
        EventBus.getDefault().register(this);
        setTitle(view, "宠物详情");
        tvName.setText(pet.getName());
        tvType.setText(pet.getType());
        tvSex.setText(pet.getGender());

    }

    @Override
    public PetPresenter createPresenter() {
        return new PetPresenter();
    }

    @Override
    public IPetContract.View createView() {
        return this;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
    }

    @OnClick({R.id.tv_info})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_info:
                getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.pet_content, new EditPetFragment()).commit();
                break;
        }
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void getPet(Pet pet) {
        if (pet != null) {
            this.pet = pet;
        } else {
            this.pet = new Pet();
            Toast.makeText(getContext(), "数据获取失败!", Toast.LENGTH_LONG).show();
        }
    }

}
